package Exer_HiHaiHi;

import org.junit.Test;

import java.io.File;
import java.io.FileInputStream;
import java.lang.reflect.Constructor;
import java.util.Properties;

/**
 * @author Jimmy Zhan WORKSTATION
 * @date 2023/4/3 15:31
 * 说明：
 */

public class JuicerTest {
    @Test
    public void test1() throws Exception{
        // 1. 读取配置文件中的信息，获取全类名测试
        Properties pro = new Properties();

        File file = new File("src/Exer_HiHaiHi/config.properties");
        FileInputStream fis = new FileInputStream(file);
        pro.load(fis);
        String fruitName = pro.getProperty("fruitName");

        // 2. 通过反射，创建指定全类名对应的类的实例
        Class<?> clazz = Class.forName(fruitName);
        Constructor<?> con = clazz.getDeclaredConstructor();
        con.setAccessible(true);

        Fruit f = (Fruit)con.newInstance();
        // 3. 通过榨汁机的对象调用run()
        Juicer juicer = new Juicer();
        juicer.run(f);
    }
}
